import React, { Component } from "react";
import {
    Route,
    Switch,
    Redirect,
    withRouter
} from "react-router-dom";
import Home from "../pages/home/home";
import Footer from "./Footer";
import Cate from "../pages/cate";
import Cart from "../pages/cart";
import User from "../pages/user";
import Login from "../pages/login";
import Reg from "../pages/reg";
import Detail from "../pages/detail";

class App extends Component {
    state = {
        bannerData: null,
        bFoot: true,
    };
    componentDidMount() {
        // console.log(this.props)
        if (/detail/.test(this.props.location.pathname)) {
            this.setState({
                bFoot: false,
            });
        }
        if (/home|cate|cart|user/.test(this.props.location.pathname)) {
            this.setState({
                bFoot: true
            })
        }
    }
    render() {
        return (
            <div className="App">
                <Switch>
                    <Route path="/home" exact component={Home} />
                    <Route path="/cate" exact component={Cate} />
                    <Route path="/cart" exact component={Cart} />
                    <Route path="/user" exact component={User} />
                    <Route path="/login" exact component={Login} />
                    <Route path="/reg" exact component={Reg} />
                    <Route path="/detail/:id" exact component={Detail} />

                    <Redirect from="/" to="/home" exact />
                </Switch>
                {this.state.bFoot && <Footer />}
            </div>
        );
    }
}

export default withRouter(App);
